#include <bitset>
#include "dialog.h"
#include "ui_dialog.h"

using namespace std;

Dialog::Dialog(QWidget* parent) :
    QDialog(parent),
    ui(new Ui::Dialog)
{
    ui->setupUi(this);
}

Dialog::~Dialog()
{
    delete ui;
}

QString Dialog::itemName()
{
    return ui->itemName->text();
}

QString Dialog::itemLevel()
{
    return ui->itemLevel->text();
}

QString Dialog::requiredLevel()
{
    return ui->requiredLevel->text();
}

QString Dialog::maxCount()
{
    return ui->maxCount->text();
}

QString Dialog::price()
{
    return ui->price->text();
}

QString Dialog::rarity()
{
    QString str;
    int i = ui->rarity->currentIndex();

    str.append(QString("%1").arg(i));
    return str;
}

QString Dialog::description()
{
    return ui->description->toPlainText();
}

QString Dialog::armor()
{
    return ui->armor->text();
}

QString Dialog::damage()
{
    return ui->damage->text();
}

QString Dialog::attackSpeed()
{
    return ui->attackSpeed->text();
}

QString Dialog::availableClasses()
{
    QString str;
    int i = 0;

    if (ui->classKnight->isChecked()) i += 1;
    if (ui->classThief->isChecked()) i += 2;
    if (ui->classSorcerer->isChecked()) i += 4;
    if (ui->classCleric->isChecked()) i += 8;
    if (ui->classArcher->isChecked()) i += 16;

    str.append(QString("%1").arg(i));
    return str;
}

QString Dialog::strBonus()
{
    return ui->strBonus->text();
}

QString Dialog::dexBonus()
{
    return ui->dexBonus->text();
}

QString Dialog::staBonus()
{
    return ui->staBonus->text();
}

QString Dialog::intBonus()
{
    return ui->intBonus->text();
}

QString Dialog::wilBonus()
{
    return ui->wilBonus->text();
}

void Dialog::setItemName(QString str)
{
    ui->itemName->setText(str);
}

void Dialog::setItemLevel(QString str)
{
    ui->itemLevel->setText(str);
}

void Dialog::setRequiredLevel(QString str)
{
    ui->requiredLevel->setText(str);
}

void Dialog::setMaxCount(QString str)
{
    ui->maxCount->setText(str);
}

void Dialog::setPrice(QString str)
{
    ui->price->setText(str);
}

void Dialog::setRarity(QString str)
{
    ui->rarity->setCurrentIndex(str.toInt());
}

void Dialog::setDescription(QString str)
{
    ui->description->setText(str);
}

void Dialog::setArmor(QString str)
{
    ui->armor->setText(str);
}

void Dialog::setDamage(QString str)
{
    ui->damage->setText(str);
}

void Dialog::setAttackSpeed(QString str)
{
    ui->attackSpeed->setText(str);
}

void Dialog::setAvailableClasses(QString str)
{
    /*unsigned char flags = str.toInt();

    if (!(flags & 0x1)) ui->classKnight->setChecked(false);
    if (!(flags & 0x2)) ui->classThief->setChecked(false);
    if (!(flags & 0x4)) ui->classSorcerer->setChecked(false);
    if (!(flags & 0x8)) ui->classCleric->setChecked(false);
    if (!(flags & 0x16)) ui->classArcher->setChecked(false);*/

    bitset<5> flags(str.toInt());
    if (!flags.test(0)) ui->classKnight->setChecked(false);
    if (!flags.test(1)) ui->classThief->setChecked(false);
    if (!flags.test(2)) ui->classSorcerer->setChecked(false);
    if (!flags.test(3)) ui->classCleric->setChecked(false);
    if (!flags.test(4)) ui->classArcher->setChecked(false);
}

void Dialog::setStrBonus(QString str)
{
    ui->strBonus->setText(str);
}

void Dialog::setDexBonus(QString str)
{
    ui->dexBonus->setText(str);
}

void Dialog::setStaBonus(QString str)
{
    ui->staBonus->setText(str);
}

void Dialog::setIntBonus(QString str)
{
    ui->intBonus->setText(str);
}

void Dialog::setWilBonus(QString str)
{
    ui->wilBonus->setText(str);
}
